package com.example.emergencyattempt01.user;

import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

public abstract class User {
    public abstract String getUserName();
    public abstract String getUserType();
    public abstract long getUid();
    public abstract String getIdentity();
    public abstract String getInstitute();
    public abstract int getOwnBooks();
    public abstract String getPassword();

    public abstract void setUserName(String userName);
    public abstract void setUserType(String userType);
    public abstract void setIdentity(String identity);
    public abstract void setPassword(String password);
    public abstract void setOwnBooks(int ownBooks);
    public abstract void setInstitute(String institute);
    public abstract void setUid(long uid);

    public static void initUser(Context context,User user)
    {
        // 编写完成登录之后，按如下执行
        SharedPreferences sharedPreferences=context.getSharedPreferences("personal_information",MODE_PRIVATE);
        user.setUid(sharedPreferences.getLong("uid",0));
        user.setOwnBooks(sharedPreferences.getInt("ownBooks",0));
        user.setUserName(sharedPreferences.getString("userName",null));
        user.setInstitute(sharedPreferences.getString("institute",null));
        user.setIdentity(sharedPreferences.getString("identity",null));
        user.setUserType(sharedPreferences.getString("userType",null));
        user.setPassword(sharedPreferences.getString("password",null));
    }
}
